package Gui;
import java.util.HashMap;

import Command.MainCommand;

import com.cloudgarden.resource.SWTResourceManager;

import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
/**
* Description :remove a direct from DB
* <p>
*
*@author Danielle
*/
public class RemoveData extends org.eclipse.swt.widgets.Composite {

	{
		//Register as a resource user - SWTResourceManager will
		//handle the obtaining and disposing of resources
		SWTResourceManager.registerResourceUser(this);
	}
	
	private Composite allView;
	private Label selectItem;
	private Button cancel;
	private Button remove;
	private Button[] select;
	static Shell shell;
	static String[] returnString;
	

	private static MainCommand mainCommand;
	/**
	* Auto-generated main method to display this 
	* org.eclipse.swt.widgets.Composite inside a new Shell.
	*/
	
	/**
	* Overriding checkSubclass allows this class to extend org.eclipse.swt.widgets.Composite
	*/	
	protected void checkSubclass() {
	}
	
	/**
	* Auto-generated method to display this 
	* org.eclipse.swt.widgets.Composite inside a new Shell.
	*/
	public static String[] showGUI(MainCommand mainCmd) {
		mainCommand=mainCmd;
		Display display = Display.getDefault();
		shell = new Shell(display);
		RemoveData inst = new RemoveData(shell, SWT.NULL);
		Point size = inst.getSize();
		shell.setLayout(new FillLayout());
		shell.layout();
		if(size.x == 0 && size.y == 0) {
			inst.pack();
			shell.pack();
		} else {
			Rectangle shellBounds = shell.computeTrim(0, 0, size.x, size.y);
			shell.setSize(shellBounds.width, shellBounds.height);
		}
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		return returnString;
	}

	public RemoveData(org.eclipse.swt.widgets.Composite parent, int style) {
		super(parent, style);
		initGUI();
	}

	private void initGUI() {
		try {
			FormLayout thisLayout = new FormLayout();
			this.setLayout(thisLayout);
			{
				allView = new Composite(this, SWT.NONE);
				FormLayout allViewLayout = new FormLayout();
				FormData allViewLData = new FormData();
				allViewLData.left =  new FormAttachment(0, 1000, 0);
				allViewLData.top =  new FormAttachment(0, 1000, -4);
				allViewLData.width = 667;
				allViewLData.height = 591;
				allView.setLayoutData(allViewLData);
				allView.setLayout(allViewLayout);
				{
					selectItem = new Label(allView, SWT.NONE);
					FormData selectItemLData = new FormData();
					selectItemLData.left =  new FormAttachment(0, 1000, 30);
					selectItemLData.top =  new FormAttachment(0, 1000, 12);
					selectItemLData.width = 301;
					selectItemLData.height = 16;
					selectItem.setLayoutData(selectItemLData);
					selectItem.setText("Select which file/folder you would like to remove:");
					selectItem.setFont(SWTResourceManager.getFont("Tahoma", 10, 0, false, false));
				}
				
				int i;
				String str;
				final String[] list=mainCommand.returnAllSource();
				int size=(list).length;
				select=new Button[size];
				
				for(i=0; i<size; i++)
				{
					FormData layout=new FormData();
					layout.left =  new FormAttachment(20, 1000, 0);
					layout.top =  new FormAttachment(50, 1000, 0);
					layout.width = 700;
					layout.height = 23;
					layout.left =  new FormAttachment(20, 1000, 0);
					layout.top =  new FormAttachment(50+30*i, 1000, 0);
					
					select[i] = new Button(allView, SWT.CHECK | SWT.LEFT);
					select[i].setLayoutData(layout);
					str= "" +list[i];
					select[i].setText(str);
					select[i].setSelection(true);
					
				}
				{
					remove = new Button(allView, SWT.PUSH | SWT.CENTER);
					FormData removeLData = new FormData();
					removeLData.left =  new FormAttachment(0, 1000, 480);
					removeLData.top =  new FormAttachment(0, 1000, 548);
					removeLData.width = 75;
					removeLData.height = 25;
					remove.setLayoutData(removeLData);
					remove.setText("Remove");
					remove.setFont(SWTResourceManager.getFont("Tahoma",9,0,false,false));
					remove.addSelectionListener(new SelectionAdapter() {
						public void widgetSelected(SelectionEvent evt) {
							int counter=0;
							int size=list.length;
							int i;
							for(i=0; i<size; i++)
							{
								if(select[i].getSelection())
									counter++;
							}
							int places=counter;
							counter=0;
							returnString=new String[places];
							for(i=0; i<size; i++)
							{
								if(select[i].getSelection())
									returnString[counter]=list[i];
							}
							shell.dispose();
							//TODO add your code for remove.widgetSelected
						}
					});
				}
				{
					cancel = new Button(allView, SWT.PUSH | SWT.CENTER);
					FormData cancelLData = new FormData();
					cancelLData.left =  new FormAttachment(0, 1000, 579);
					cancelLData.top =  new FormAttachment(0, 1000, 548);
					cancelLData.width = 76;
					cancelLData.height = 25;
					cancel.setLayoutData(cancelLData);
					cancel.setText("cancel");
					cancel.setFont(SWTResourceManager.getFont("Tahoma",9,0,false,false));
					cancel.addSelectionListener(new SelectionAdapter() {
						public void widgetSelected(SelectionEvent evt) {
							returnString=null;
							shell.dispose();
							//TODO add your code for cancel.widgetSelected
						}
					});
				}
			}
			this.layout();
			pack();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
